package com.example.text0926;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.widget.TextView;

public class MainActivity2_1 extends AppCompatActivity {
    TextView textView;
    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("mml","A2_1:This is OnRestart!");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("mml","A2_1:This is OnPause!");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("mml","A2_1:This is OnResume!");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("mml","A2_1:This is OnStart!");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("mml","A2_1:This is OnStop!");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("mml","A2_1:This is OnDestory!");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main2_1);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        Log.d("mml","A2_1:This is OnCreate!");

        textView = findViewById(R.id.textView_name);

        //获取activity2的intent，使用getIntent()
        Intent intent = getIntent();
        String str = intent.getStringExtra("name");//参数：name = key
        textView.setText(str);
        int age = intent.getIntExtra("age",1);//参数：age = key, 默认值--->说明数据类型
        textView.setText(str+" "+age);
        Bundle bundle=intent.getExtras();
        String str2 = bundle.getString("name")+bundle.getInt("age");
        textView.setText(str2);
    }

}